<?php
class BaseRelax extends Zend_Db_Table
{   
    protected $_name = "relax";
    
    /**
    * Class constructor
    * @return void
    */    
	function __construct($config = null){
        parent::__construct();
        
        
        $this->id = 0;
        
        $this->category = 0;
        
        $this->title_vi = "";
        
        $this->title_en = "";
        
        $this->short_content_en = "";
        
        $this->short_content_vi = "";
        
        $this->description_en = "";
        
        $this->description_vi = "";
        
        $this->created = date("Y-m-d H:i:s");
        
        $this->phone = "";
        
        $this->image = "";
        
        $this->website = "";
        
        $this->address_vi = "";
        
        $this->address_en = "";
        
    }
	
    function clearData()
    {
        
        $this->id = 0;
        
        $this->category = 0;
        
        $this->title_vi = "";
        
        $this->title_en = "";
        
        $this->short_content_en = "";
        
        $this->short_content_vi = "";
        
        $this->description_en = "";
        
        $this->description_vi = "";
        
        $this->created = date("Y-m-d H:i:s");
        
        $this->phone = "";
        
        $this->image = "";
        
        $this->website = "";
        
        $this->address_vi = "";
        
        $this->address_en = "";
        
    }
    
	/**
	All property of class
	*/
    
    /*
	* @declare   id of  Relax
	*/
    protected $id;
    
    /*
	* @declare   category of  Relax
	*/
    protected $category;
    
    /*
	* @declare   title_vi of  Relax
	*/
    protected $title_vi;
    
    /*
	* @declare   title_en of  Relax
	*/
    protected $title_en;
    
    /*
	* @declare   short_content_en of  Relax
	*/
    protected $short_content_en;
    
    /*
	* @declare   short_content_vi of  Relax
	*/
    protected $short_content_vi;
    
    /*
	* @declare   description_en of  Relax
	*/
    protected $description_en;
    
    /*
	* @declare   description_vi of  Relax
	*/
    protected $description_vi;
    
    /*
	* @declare   created of  Relax
	*/
    protected $created;
    
    /*
	* @declare   phone of  Relax
	*/
    protected $phone;
    
    /*
	* @declare   image of  Relax
	*/
    protected $image;
    
    /*
	* @declare   website of  Relax
	*/
    protected $website;
    
    /*
	* @declare   address_vi of  Relax
	*/
    protected $address_vi;
    
    /*
	* @declare   address_en of  Relax
	*/
    protected $address_en;
    
    
    /**
        All method of Relax
    */
    
    /**
     * @desc this method will set the value of the $id property
     * @param int  $id
     * @return void
     */
     function setId($id)
     {
        $this->id = $id;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $id property 
     * @param void
     * @return int of $id
     */
     function getId()
     {
        return  $this->id;
     } // end get function
     
    /**
     * @desc this method will set the value of the $category property
     * @param int  $category
     * @return void
     */
     function setCategory($category)
     {
        $this->category = $category;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $category property 
     * @param void
     * @return int of $category
     */
     function getCategory()
     {
        return  $this->category;
     } // end get function
     
    /**
     * @desc this method will set the value of the $title_vi property
     * @param varchar  $title_vi
     * @return void
     */
     function setTitleVi($title_vi)
     {
        $this->title_vi = $title_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $title_vi property 
     * @param void
     * @return varchar of $title_vi
     */
     function getTitleVi()
     {
        return  $this->title_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $title_en property
     * @param varchar  $title_en
     * @return void
     */
     function setTitleEn($title_en)
     {
        $this->title_en = $title_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $title_en property 
     * @param void
     * @return varchar of $title_en
     */
     function getTitleEn()
     {
        return  $this->title_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $short_content_en property
     * @param mediumtext  $short_content_en
     * @return void
     */
     function setShortContentEn($short_content_en)
     {
        $this->short_content_en = $short_content_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $short_content_en property 
     * @param void
     * @return mediumtext of $short_content_en
     */
     function getShortContentEn()
     {
        return  $this->short_content_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $short_content_vi property
     * @param mediumtext  $short_content_vi
     * @return void
     */
     function setShortContentVi($short_content_vi)
     {
        $this->short_content_vi = $short_content_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $short_content_vi property 
     * @param void
     * @return mediumtext of $short_content_vi
     */
     function getShortContentVi()
     {
        return  $this->short_content_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $description_en property
     * @param mediumtext  $description_en
     * @return void
     */
     function setDescriptionEn($description_en)
     {
        $this->description_en = $description_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $description_en property 
     * @param void
     * @return mediumtext of $description_en
     */
     function getDescriptionEn()
     {
        return  $this->description_en;
     } // end get function
     
    /**
     * @desc this method will set the value of the $description_vi property
     * @param mediumtext  $description_vi
     * @return void
     */
     function setDescriptionVi($description_vi)
     {
        $this->description_vi = $description_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $description_vi property 
     * @param void
     * @return mediumtext of $description_vi
     */
     function getDescriptionVi()
     {
        return  $this->description_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $created property
     * @param datetime  $created
     * @return void
     */
     function setCreated($created)
     {
        $this->created = $created;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $created property 
     * @param void
     * @return datetime of $created
     */
     function getCreated()
     {
        return  $this->created;
     } // end get function
     
    /**
     * @desc this method will set the value of the $phone property
     * @param varchar  $phone
     * @return void
     */
     function setPhone($phone)
     {
        $this->phone = $phone;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $phone property 
     * @param void
     * @return varchar of $phone
     */
     function getPhone()
     {
        return  $this->phone;
     } // end get function
     
    /**
     * @desc this method will set the value of the $image property
     * @param varchar  $image
     * @return void
     */
     function setImage($image)
     {
        $this->image = $image;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $image property 
     * @param void
     * @return varchar of $image
     */
     function getImage()
     {
        return  $this->image;
     } // end get function
     
    /**
     * @desc this method will set the value of the $website property
     * @param varchar  $website
     * @return void
     */
     function setWebsite($website)
     {
        $this->website = $website;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $website property 
     * @param void
     * @return varchar of $website
     */
     function getWebsite()
     {
        return  $this->website;
     } // end get function
     
    /**
     * @desc this method will set the value of the $address_vi property
     * @param varchar  $address_vi
     * @return void
     */
     function setAddressVi($address_vi)
     {
        $this->address_vi = $address_vi;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $address_vi property 
     * @param void
     * @return varchar of $address_vi
     */
     function getAddressVi()
     {
        return  $this->address_vi;
     } // end get function
     
    /**
     * @desc this method will set the value of the $address_en property
     * @param varchar  $address_en
     * @return void
     */
     function setAddressEn($address_en)
     {
        $this->address_en = $address_en;
     } // end set function 
     
     /**
     * @desc this method will return the value of the $address_en property 
     * @param void
     * @return varchar of $address_en
     */
     function getAddressEn()
     {
        return  $this->address_en;
     } // end get function
       
     
     
     /**
     * @desc this function get Relax  by $id
     * @var int : $id 
     * @var 
     * @return Relax object
     */
     function getById($id)
     {
          $row = $this->fetchRow("id='$id'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $category
     * @var int : $category 
     * @var 
     * @return Relax object
     */
     function getByCategory($category)
     {
          $row = $this->fetchRow("category='$category'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $title_vi
     * @var varchar : $title_vi 
     * @var 
     * @return Relax object
     */
     function getByTitleVi($title_vi)
     {
          $row = $this->fetchRow("title_vi='$title_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $title_en
     * @var varchar : $title_en 
     * @var 
     * @return Relax object
     */
     function getByTitleEn($title_en)
     {
          $row = $this->fetchRow("title_en='$title_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $short_content_en
     * @var mediumtext : $short_content_en 
     * @var 
     * @return Relax object
     */
     function getByShortContentEn($short_content_en)
     {
          $row = $this->fetchRow("short_content_en='$short_content_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $short_content_vi
     * @var mediumtext : $short_content_vi 
     * @var 
     * @return Relax object
     */
     function getByShortContentVi($short_content_vi)
     {
          $row = $this->fetchRow("short_content_vi='$short_content_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $description_en
     * @var mediumtext : $description_en 
     * @var 
     * @return Relax object
     */
     function getByDescriptionEn($description_en)
     {
          $row = $this->fetchRow("description_en='$description_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $description_vi
     * @var mediumtext : $description_vi 
     * @var 
     * @return Relax object
     */
     function getByDescriptionVi($description_vi)
     {
          $row = $this->fetchRow("description_vi='$description_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $created
     * @var datetime : $created 
     * @var 
     * @return Relax object
     */
     function getByCreated($created)
     {
          $row = $this->fetchRow("created='$created'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $phone
     * @var varchar : $phone 
     * @var 
     * @return Relax object
     */
     function getByPhone($phone)
     {
          $row = $this->fetchRow("phone='$phone'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $image
     * @var varchar : $image 
     * @var 
     * @return Relax object
     */
     function getByImage($image)
     {
          $row = $this->fetchRow("image='$image'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $website
     * @var varchar : $website 
     * @var 
     * @return Relax object
     */
     function getByWebsite($website)
     {
          $row = $this->fetchRow("website='$website'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $address_vi
     * @var varchar : $address_vi 
     * @var 
     * @return Relax object
     */
     function getByAddressVi($address_vi)
     {
          $row = $this->fetchRow("address_vi='$address_vi'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
     
     /**
     * @desc this function get Relax  by $address_en
     * @var varchar : $address_en 
     * @var 
     * @return Relax object
     */
     function getByAddressEn($address_en)
     {
          $row = $this->fetchRow("address_en='$address_en'");
          if($row)
            $this->fromArray($row->toArray());
          return $this;
     }
       
     
     // function save ".trimplural($table)." 
     public function save($forceInsert= false)
     { 
         if( $forceInsert == true)
            return $this->insert($this->toArray());
         $update = false;
         $condition = array(); 
        
        if($this->getId())
        {
            // is update
            $update = true;
            $condition[] = "id ='". $this->getId() ."'";
        }
        
         if( $update )   // update Relax
         {
            return $this->update($this->toArray(),implode(" and ",$condition));
         }
         else
         {
             $this->insert($this->toArray());
         }
     }
     /**
     * @desc this function get list of ".$table."
     * @var int : string $where condition, $page is current page, $rowCount is total row
     * @var 
     * @return user object
     */
     public function getListRelax($where = null,$order = array(),$page = null ,$rowCount = null)
     {
        $select =  $this->select();
        if($where != null)
            $select->where($where);
         if($page===null)
             $select->from($this->_name);
        else
           $select->from($this->_name)->limitPage($page,$rowCount);
        $select->order($order);
        return $this->fetchAll($select);
     }     
     
     /**
     * @desc this method will import data from array 
     * @param void
     * @return array
     */
     function fromArray($array)
     {
        // import all proper ty
        
        if(isset($array["id"]))
                $this->id = $array["id"];
        
        if(isset($array["category"]))
                $this->category = $array["category"];
        
        if(isset($array["title_vi"]))
                $this->title_vi = $array["title_vi"];
        
        if(isset($array["title_en"]))
                $this->title_en = $array["title_en"];
        
        if(isset($array["short_content_en"]))
                $this->short_content_en = $array["short_content_en"];
        
        if(isset($array["short_content_vi"]))
                $this->short_content_vi = $array["short_content_vi"];
        
        if(isset($array["description_en"]))
                $this->description_en = $array["description_en"];
        
        if(isset($array["description_vi"]))
                $this->description_vi = $array["description_vi"];
        
        if(isset($array["created"]))
                $this->created = $array["created"];
        
        if(isset($array["phone"]))
                $this->phone = $array["phone"];
        
        if(isset($array["image"]))
                $this->image = $array["image"];
        
        if(isset($array["website"]))
                $this->website = $array["website"];
        
        if(isset($array["address_vi"]))
                $this->address_vi = $array["address_vi"];
        
        if(isset($array["address_en"]))
                $this->address_en = $array["address_en"];
        
        // return object
        return $this;
     } // end export function
     
     /**
     * @desc this method will export data to array 
     * @param void
     * @return array
     */
     function toArray()
     {
        // import all proper ty
        $array = array();
        
        $array["id"] = $this->id;
        
        $array["category"] = $this->category;
        
        $array["title_vi"] = $this->title_vi;
        
        $array["title_en"] = $this->title_en;
        
        $array["short_content_en"] = $this->short_content_en;
        
        $array["short_content_vi"] = $this->short_content_vi;
        
        $array["description_en"] = $this->description_en;
        
        $array["description_vi"] = $this->description_vi;
        
        $array["created"] = $this->created;
        
        $array["phone"] = $this->phone;
        
        $array["image"] = $this->image;
        
        $array["website"] = $this->website;
        
        $array["address_vi"] = $this->address_vi;
        
        $array["address_en"] = $this->address_en;
        
        // return object
        return $array;
     } // end export function
     
    function numRows($where = null)
    {
        $select = $this->_db->select();
        $select->from($this->_name, "COUNT(*)", $this->_schema);
        // the WHERE clause
        $where = (array) $where;
        foreach ($where as $key => $val) {
            // is $key an int?
            if (is_int($key)) {
                // $val is the full condition
                $select->where($val);
            } else {
                // $key is the condition with placeholder,
                // and $val is quoted into the condition              
                $select->where($key, $val);           
            }          
        }
        // return the results
        $stmt = $this->_db->query($select);
        
        $data = $stmt->fetchColumn(0);       
        return $data;  
    }              
}